package dongshi.daddy;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class HibernateJpaMain {
    public static void main(String[] args) {
        //创建Hibernate核心类
        Configuration cfg=new Configuration();
        //读取核心配置文件
        cfg.configure("hibernate.cfg.xml");
        //创建session工厂
        SessionFactory sf = cfg.buildSessionFactory();
        //获取session
        Session session = sf.openSession();
        //开启事务
        Transaction ts= session.beginTransaction();
        System.out.println("-------------增加-------------------");
        //新增
		User user=new User(111, "阿三同学");
		session.save(user);
        ts.commit();
    }
}
